﻿using EnvDTE;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Axiom.CodeManifold
{
	public static class DteExtensions
	{
		public static IList<FileCodeModel> AllCodeModels(this EnvDTE.DTE dte)
		{
			if (dte.Solution == null)
			{
				throw new SolutionNotFoundException("No solution found");
			}

			var results = new List<FileCodeModel>();

			var projects = dte.AllProjects();

			foreach (var project in projects)
			{
				foreach (FileCodeModel codemodel in project.GetCodeModels())
				{
					results.Add(codemodel);
				}
			}

			return results;
		}

		public static IList<Project> AllProjects(this EnvDTE.DTE dte)
		{
			if (dte.Solution.Projects == null || dte.Solution.Projects.Item(1) == null)
			{
				throw new SolutionNotFoundException("No projects in solution");
			}

			return new List<Project>(dte.Solution.OfType<Project>());
		}
	}
}
